package demo1;

public class Test1 {
    public static void main(String[] args) {

        ListNode a = new ListNode(1);
        ListNode b = new ListNode(2);
        ListNode c = new ListNode(3 );
        a.next = b ;
        b.next = c ;
         ListNode h = fz(a) ;
      display(a);
         display(h);
    }

    public static ListNode fz(ListNode head) {
        ListNode prev = null ;
        ListNode cur = head ;
        while(cur != null){
            ListNode curNext = cur.next ;
            cur.next = prev ;
            prev = cur ;
            cur = curNext;
        }
        return prev ;
    }
     public static void display(ListNode head){
        ListNode ret = head ;
        while (ret != null){
            System.out.print(ret.val + "  ");
            ret = ret.next ;
        }
         System.out.println();
     }

}
